package com.sskj.gocoin.common;

import com.sskj.gocoin.common.event.TimeEvent;
import com.sskj.gocoin.common.rxbus2.RxBus;
import com.sskj.gocoin.utils.RxSchedulersHelper;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;

public class TimerUtil {


    public static void time(int time) {
        Observable.interval(0, 1, TimeUnit.SECONDS)
                .compose(RxSchedulersHelper.io_main())
                .map(increaseTime -> time - increaseTime).take(time + 1)
                .subscribe(t -> {
                    RxBus.getDefault().post(new TimeEvent(t));
                });
    }
}
